package com.dyw;

import com.dyw.Domain.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @auther Devil(丁杨维)
 * @create 2021-12-28-15:15
 */
public class MyApp {
    public static void main(String[] args) throws IOException {
        //访问mybatis读取student数据
        //1.定义mybatis主配置文件的名称 ,从类路径开始(target/classes)
        String config = "mybatis.xml";

        InputStream In = Resources.getResourceAsStream(config);

        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();

        SqlSessionFactory factory = builder.build(In);

        SqlSession sqlSession = factory.openSession();
        //[重要]
        String sqlId = "com.dyw.Dao.StudentDao"+"."+"selectStudent";
        //[重要]
        List<Student> studentList = sqlSession.selectList(sqlId);

        //输出
        for (Student student : studentList) {
            System.out.println(student);
        }

        sqlSession.close();


    }
}
